/**
 * Created by haocongshun on 2016/9/8.
 */
var contextPath = "/";
$(function () {
    contextPath += window.location.pathname.split("/")[1];
    $("#toptitle").html("查看优秀作业");
    init();
    $("#jobTask").change(function () {
        initGoodJob();
    });
});
function init(){
    initJobTask();
    initGoodJob();
}
function initJobTask() {
    var dataInit = {};
    var url = contextPath+"/LookUpGoodJob/jobTask.wm";
    $.ajaxSetup({
        async : false
    });
    $.post(url,dataInit,function (result) {
        var option = "";
        for(var i = 0;i < result.jobTask.length;i++){
            if(result.jobTask[i].jobTask_title==null||result.jobTask[i].jobTask_title==""){
                continue;
            }
            option+="<option value='"+result.jobTask[i].jobTask_id+"'>"+result.jobTask[i].jobTask_title+"</option>"
        }
        $("#jobTask").html(option);
    },"json");
}
function initGoodJob() {
    var dataInit = {};
    dataInit.jobTask_id = $("#jobTask option:selected").val();
    var url = contextPath+"/LookUpGoodJob/goodJob.wm";
    $.post(url,dataInit,function (result) {
        var content = "";
        for(var i = 0;i < result.goodJob.length;i++){
            var temp = result.goodJob[i].work_date.replace(/-/g,'/');
            temp.substring(0,temp.length-2)
            content += " <tr>"+
                "<td>"+result.goodJob[i].aStudent.student_number+"</td>"+
                "<td></a>"+result.goodJob[i].aStudent.student_name+"</td>"+
                "<td><a href='"+contextPath+"/LookUpGoodJob/downloadGoodJob.wm?id="+result.goodJob[i].work_id+"'>"+result.goodJob[i].work_title+"</a></td>"+
                "<td><a href='"+contextPath+"/LookUpGoodJob/downloadGoodJob.wm?id="+result.goodJob[i].work_id+"'>下载附件</a></td>"+
                "</tr>"
        }
        if(content==null||content==""){
            $("#table_demo3 tbody").html("<div class='king-notice-box king-notice-sad'> <p class='king-notice-text'>该作业任务下面还没有优秀作业！ </p> </div>");
            $("#page").html("");
        }
        else {
            $("#table_demo3 tbody").html(content);
            $("#page span").html($("#table_demo3 tbody tr").length);
        }

    },"json");
}